function Anthor(){}

$.extend(Anthor.prototype , {
    init : function(){
        console.log("i am anthor");
        this.anchor = $(".anchor");
        this.header   = $("#television");

        this.headerSize = {
            height : this.header.height()
        }
        this.anchor_list = this.anchor.find("li");
        this.commit = $(".television");
        this.commit_list = [];
        
        $.each(this.commit ,$.proxy(function(index,item){
            var min = $(item).offset().top;
            this.commit_list.push({
                min : min,
                max : min + $(item).outerHeight()
            })
        },this));
       
        $(window).on("scroll",$.proxy(this.changeAnchor,this));
        this.anchor.on("click","li" , $.proxy(this.changeFloor,this));
    },
    changeAnchor : function(){
        var scrollTop = $("html,body").scrollTop();
        this.showAnchor(scrollTop);
        this.changeStairs(scrollTop+100);
    },
    showAnchor : function(scrollTop){
        if(scrollTop >= 600 || this.clientHeight >= 600){
            this.anchor.fadeIn(500).css("display","block");
        }else{
            this.anchor.fadeOut(500);       
        }
    },
    changeStairs : function(scrollTop){     
        $.each( this.commit_list , $.proxy( function(index,item){
            scrollTop >= item.min && scrollTop < item.max && $(this.anchor_list).eq(index).addClass("active")
            .siblings().removeClass("active");
        },this))
    },
    changeFloor : function(evt){
        var e = evt || window.event;
        var target = e.target || e.srcElement;
        var index = 0;
        // var index = $(target).index();
        target.nodeName !== "LI" && (index = $(target).closest("li").index());
        $("html,body").animate({
            scrollTop : $(this.commit).eq(index).offset().top
        },1000)
    }
})

export default new Anthor();